
public class Binary {
    public static void main(String[] args) {
        int[] Array = {1, 2, 3, 4, 5, 6, 7, 8, 9};
        int tem = 6;

        int Right = Array.length - 1;
        int Left = 0;
        boolean flag = false;

        while (flag == false){
            int Middle = (Left + Right)/2;
            if(tem == Array[Middle]){
                System.out.println("找到了，下标为"+Middle);
                flag = true;
            }else if(tem < Array[Middle]){
                Right = Middle;
            }else if(tem > Array[Middle]){
                Left = Middle;
            } else {
                System.out.println("所输入数值在数组中不存在");
            }
        }
    }
}
